/**
 * 登录请求
 */
function sure_log_in(){
	var user_id = $("#input_user_id").val().trim();
	var user_pd = $("#input_user_password").val().trim();
	var code = $("#input_key_number").val().trim();
	var else_1 = "";//备用字段，用于超时
	if(user_id == null || user_id ==""){
		alert("用户ID不能为空");
		return;
	}
	if(user_pd == null || user_pd == ""){
		alert("密码不能为空");
		return;
	}
	if(code == null || code == ""){
		alert("请填入图片对应的验证码");
		return;
	}
	//！！！！！！！！！！！！！！！！解决ajax post中文乱码！！！！
	var user_id_encode = encodeURI(user_id,"utf-8");
	var send_json = {"user_id":user_id_encode,"user_pwd":user_pd,"key_code":code,"else_1":else_1};
	$.ajax({
		url:"log_in.do",
		dataType: 'json',
        contentType : "application/json",
        type: "post",
        data: JSON.stringify(send_json),
        success: function(data) {
        	if(data.code != "0001"){
        		if(data.data != ""){
            		$("#key_img").attr("src","data:image/png;base64,"+data.data);
            	}
        		alert(data.msg);
        		return;
        	}
        	//手动清除原来的存值
        	window.localStorage.clear();
        	//记录用户信息到localStorage
        	window.localStorage.setItem("user_id", user_id);
        	window.localStorage.setItem("user_nickname", data.data);
        	window.location.href="vip_enter.html";
        },
        error:function(data) {
        	alert("系统繁忙，请稍后重试");
        }
	})
	
}

/**
 * 注册请求
 */
function sure_regist(){
	var temp_code = "1";
	var temp_msg = "";
	var user_id = $("#input_user_id").val().trim();
	var pwd = $("#input_user_password").val().trim();
	var pwd2 = $("#input_user_password2").val().trim();
	var key_code = $("#input_key_number").val().trim();
	var user_phone = $("#input_user_phone").val().trim();
	var user_email = $("#input_user_email").val().trim();
	var key_code = $("#input_key_number").val().trim();
	var else_1 = "";//备用字段，用于超时
	if(user_id == ""){
		temp_code = "0";
		temp_msg = "ID不能为空";
	} else if(pwd == ""){
		temp_code = "0";
		temp_msg = "请设置密码";
	} else if(pwd2 == ""){
		temp_code = "0";
		temp_msg = "请确认密码";
	} else if(pwd != pwd2){
		temp_code = "0";
		temp_msg = "两次密码不一致";
	} else if(key_code == ""){
		temp_code = "0";
		temp_msg = "请输入图片验证码";
	}
	if(temp_code != "1"){
		alert(temp_msg);
		return;
	}
	//console.log("过了");
	var send_json = {"user_id":user_id,"user_password":pwd,"key_code":key_code,
			"else_1":else_1,"user_phone":user_phone, "user_email":user_email};
	$.ajax({
		url:"regist.action",
		dataType: 'json',
        contentType : "application/json",
        type: "post",
        data: JSON.stringify(send_json),
        success: function(data) {
        	if(data.code != "0001"){
        		if(data.data != ""){
            		$("#key_img").attr("src","data:image/png;base64,"+data.data);
            	}
        		alert(data.msg);
        		return;
        	}
        	alert(data.msg +","+ data.data);
        },
        error:function(data) {
        	alert("系统繁忙，请稍后重试");
        }
	})
}

function other_enter(){
	window.location.href="other_enter.html";
}